package com.zx.crowdfunding.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zx.crowdfunding.api.MySQLRemoteService;
import com.zx.crowdfunding.constant.CrowdFundingConstant;
import com.zx.crowdfunding.entity.vo.PortalTypeVO;
import com.zx.crowdfunding.util.ResultEntity;

/**
 * 门户 - Handler
 * @author 郑雪
 * @date 2021-12-30
 */
@Controller
public class PortalHandler {
	
	/**
	 * MySQL数据服务远程接口
	 */
	@Autowired
	private MySQLRemoteService mysqlRemoteService;

	/**
	 * 显示门户首页
	 * @return 跳转到首页
	 */
	@RequestMapping("/")
	public String showPortalPage(ModelMap modelMap) {
		
		// 1.调用远程接口获取门户首页项目分类列表
		ResultEntity<List<PortalTypeVO>> resultEntity = mysqlRemoteService.getPortalTypeProjectDataRemote();
		
		// 2.检查查询结果
		String result = resultEntity.getResult();
		
		// 3.如果成功
		if(ResultEntity.SUCCESS.equals(result)) {
			
			// 4.获取查询到的数据
			List<PortalTypeVO> data = resultEntity.getData();
			
			// 5.将数据存入模型
			modelMap.addAttribute(CrowdFundingConstant.ATTR_NAME_PORTAL_DATA, data);
		}
		
		// 6.跳转到首页
		return "portal";
	}
}
